<?php

namespace App\Model;

use App\Utility\ApiToken;

class AdminsModel extends BaseModel{

    protected $table = 'admins';

    const STATUS_1 = 1;
    const STATUS_2 = 2;
    const STATUS_TEXT = [
        self::STATUS_2 => '<span class="el-tag el-tag--danger">锁定</span>',
        self::STATUS_1 => '<span class="el-tag">正常</span>',
    ];

    protected $fillable = [
        'id','username','nickname','password','created_at','status', 'login_at','openid'
    ];

    /**
     * 获取登陆用户信息
     * @param $token
     * @return bool|null
     * @throws \EasySwoole\Mysqli\Exceptions\ConnectFail
     * @throws \EasySwoole\Mysqli\Exceptions\PrepareQueryFail
     * @throws \Throwable
     */
    public function user($token){
        $userid = ApiToken::sessionCheckToken($token);
        if($userid === false){
            return false;
        }
        return $this->find($userid);
    }





}
